package ${packageName}.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lenovo.bloom.common.log.annotation.SysLog;
import com.lenovo.bloom.tool.common.api.dto.Response;
import ${packageName}.model.dto.${classInfo.className}Dto;
import ${packageName}.model.entity.${classInfo.className};
import ${packageName}.service.I${classInfo.className}Service;
<#if swagger>
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
</#if>
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

/**
 * ${classInfo.classComment} service controller
 *
 * @author ${authorName}
 */
@RestController
@RequestMapping("/v1/${classInfo.className?uncap_first}")
@AllArgsConstructor
<#if swagger>
@Api(tags = "${classInfo.className?uncap_first}")
</#if>
public class ${classInfo.className}Controller {

    private final I${classInfo.className}Service ${classInfo.className?uncap_first}Service;

    /**
     * 分页查询${classInfo.classComment}
     *
     * @param page    分页对象
     * @param ${classInfo.className?uncap_first} ${classInfo.classComment}
     * @return 分页对象
     */
<#if swagger>
    @ApiOperation(value = "分页查询${classInfo.classComment}")
</#if>
    @GetMapping("/page")
    public Response<IPage<${classInfo.className}>> get${classInfo.className}Page(Page page, ${classInfo.className}Dto ${classInfo.className?uncap_first}) {
        return Response.ok(${classInfo.className?uncap_first}Service.get${classInfo.className}Page(page, ${classInfo.className?uncap_first}));
    }

    /**
     * 通过ID查询${classInfo.classComment}
     *
     * @param id
     * @return ${classInfo.classComment}
     */
<#if swagger>
    @ApiOperation(value = "通过ID查询${classInfo.classComment}")
    <#if classInfo.pkClass == "Long" || classInfo.pkClass == "Integer">
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id", value = "id", dataType = "string", required = true)
    )
    </#if>
</#if>
    @GetMapping("/{id}")
    public Response<${classInfo.className}> get${classInfo.className}ById(@PathVariable ${classInfo.pkClass} id) {
        return Response.ok(${classInfo.className?uncap_first}Service.get${classInfo.className}ById(id));
    }

    /**
     * 添加${classInfo.classComment}
     *
     * @param ${classInfo.className?uncap_first} ${classInfo.classComment}
     * @return id
     */
    @SysLog("添加${classInfo.classComment}")
    @PostMapping
<#if swagger>
    @ApiOperation(value = "添加${classInfo.classComment}")
</#if>
    public Response<String> save${classInfo.className}(@Valid @RequestBody ${classInfo.className} ${classInfo.className?uncap_first}) {
        return Response.ok(${classInfo.className?uncap_first}Service.save${classInfo.className}(${classInfo.className?uncap_first}));
    }

    /**
     * 修改${classInfo.classComment}
     *
     * @param ${classInfo.className?uncap_first} ${classInfo.classComment}
     * @return success/false
     */
    @PutMapping
    @SysLog("修改${classInfo.classComment}")
<#if swagger>
    @ApiOperation(value = "修改${classInfo.classComment}")
</#if>
    public Response<Boolean> update${classInfo.className}ById(@Valid @RequestBody ${classInfo.className} ${classInfo.className?uncap_first}) {
        return Response.ok(${classInfo.className?uncap_first}Service.update${classInfo.className}(${classInfo.className?uncap_first}));
    }

    /**
     * 删除${classInfo.classComment}
     *
     * @param id ID
     * @return Response
     */
    @SysLog("删除${classInfo.classComment}")
    @DeleteMapping("/{id}")
<#if swagger>
    @ApiOperation(value = "删除${classInfo.classComment}")
    <#if classInfo.pkClass == "Long" || classInfo.pkClass == "Integer">
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id", value = "id", dataType = "string", required = true)
    )
    </#if>
</#if>
    public Response remove${classInfo.className}ById(@PathVariable ${classInfo.pkClass} id) {
        ${classInfo.className?uncap_first}Service.remove${classInfo.className}ById(id);
        return Response.ok();
    }

}